package com.shxzz.easy12306.services.user.service.handler.filter.user;

import com.shxzz.easy12306.framework.starter.convention.exceptions.ClientException;
import com.shxzz.easy12306.services.user.common.enums.UserRegisterErrorCode;
import com.shxzz.easy12306.services.user.dto.req.UserRegisterReqDTO;
import com.shxzz.easy12306.services.user.service.UserLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户注册用户名存在性校验
 * @author shxzz
 * @create 2024-02-27-22:55
 */
@RequiredArgsConstructor
@Component
public class UserRegisterHasUsernameChainHandler implements UserRegisterFilter{

    private final UserLoginService userLoginService;

    @Override
    public void handler(UserRegisterReqDTO requestParam) {
        if(Boolean.FALSE.equals(userLoginService.isUsernameAvailable(requestParam.getUsername()))) {
            throw new ClientException(UserRegisterErrorCode.HAS_USERNAME_NOTNULL);
        }
    }

    @Override
    public int getOrder() {
        return 100;
    }
}
